package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.command.Command
import com.kemai.designmode.command.command.DiscountCommand
import com.kemai.designmode.command.command.HotCommand
import com.kemai.designmode.command.command.NewsCommand
import com.kemai.designmode.command.handler.DiscountHandler


//命令模式调用(通过增加command抽象命令类，将不符合抽象编程的handler调用转为抽象编程)
class CommandActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("优惠商品","热门商品","最新商品")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("命令模式")
        setAdapterContent(studyContent,CommandActivity@this,CommandActivity@this)
    }

    override fun itemClick(position: Int) {
        var command: Command? = null

        when(position){

            0->{
                command = DiscountCommand()
            }
            1->{
                command = HotCommand()
            }
            2->{
                command = NewsCommand()
            }
        }
        command?.execute()

    }

}